package com.nangle.managehost.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.nangle.managehost.R;
import com.nangle.managehost.entity.Bed;

import java.util.List;

/**
 * 作者：Administrator on 2016/9/22 17:07
 * 描述：
 */
public class  DeviceGridViewAdapter extends BaseAdapter
{
    private LayoutInflater mInflater;
    private Context mContext;
    private List<Bed> mDatas;

    public DeviceGridViewAdapter(Context context, List<Bed> mDatas)
    {
        mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.mDatas = mDatas;
    }

    @Override
    public int getCount()
    {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position)
    {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            convertView = mInflater.inflate(R
                            .layout.device_griditem, parent,
                    false);
            viewHolder = new ViewHolder();
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.iv_bed);
            viewHolder.textView = (TextView)convertView.findViewById(R.id.tv_bed_number);
            convertView.setTag(viewHolder);
        } else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.textView.setText(mDatas.get(position).getBedNumber()+"");
        if(position==12){
            viewHolder.imageView.setImageResource(R.drawable.abnormal_device);
        }else{
            viewHolder.imageView.setImageResource(R.drawable.device_icon);
        }
        return convertView;
    }

    private final class ViewHolder
    {
        private ImageView imageView;
        private TextView textView;

    }

}